package at.main.android;
/* 
 *  Convert J2ME to Android v.001
 *  Author: Van Tan Tai 
 *  Mail  : itvan@live.com
 *  Date  : 11.11.2010
 * 
 */
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class Static {
	public static Activity App = null;
	public static View view = null;
	
	public static void windowFullScreen(Activity activity)
	{
		if(null != activity)
		{
			activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN , 
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
			activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		}
	}
	
	public static int convertKey(int keyAndroid){
		switch(keyAndroid){
		case KeyEvent.KEYCODE_DPAD_DOWN: 	return -2;
		case KeyEvent.KEYCODE_DPAD_LEFT: 	return -3;
		case KeyEvent.KEYCODE_DPAD_RIGHT: 	return -4;
		case KeyEvent.KEYCODE_DPAD_UP: 		return -1;
		
		case KeyEvent.KEYCODE_ENTER:
		case KeyEvent.KEYCODE_DPAD_CENTER: 	return -5;
		
		case KeyEvent.KEYCODE_MENU: 		return CanvasJ2ME.LEFT_SOFTKEY;
		case KeyEvent.KEYCODE_BACK: 		return CanvasJ2ME.RIGHT_SOFTKEY;
		
		case KeyEvent.KEYCODE_CLEAR:		return CanvasJ2ME.CLEAR;
//		case KeyEvent.KEYCODE_DPAD_DOWN: return CanvasJ2ME.GAME_A;
//		case KeyEvent.KEYCODE_DPAD_DOWN: return CanvasJ2ME.GAME_B;
//		case KeyEvent.KEYCODE_DPAD_DOWN: return CanvasJ2ME.GAME_C;
//		case KeyEvent.KEYCODE_DPAD_DOWN: return CanvasJ2ME.GAME_D;
		
		case KeyEvent.KEYCODE_0: 		return CanvasJ2ME.KEY_NUM0;
		case KeyEvent.KEYCODE_1: 		return CanvasJ2ME.KEY_NUM1;
		case KeyEvent.KEYCODE_2: 		return CanvasJ2ME.KEY_NUM2;
		case KeyEvent.KEYCODE_3: 		return CanvasJ2ME.KEY_NUM3;
		case KeyEvent.KEYCODE_4: 		return CanvasJ2ME.KEY_NUM4;
		case KeyEvent.KEYCODE_5: 		return CanvasJ2ME.KEY_NUM5;
		case KeyEvent.KEYCODE_6: 		return CanvasJ2ME.KEY_NUM6;
		case KeyEvent.KEYCODE_7: 		return CanvasJ2ME.KEY_NUM7;
		case KeyEvent.KEYCODE_8: 		return CanvasJ2ME.KEY_NUM8;
		case KeyEvent.KEYCODE_9: 		return CanvasJ2ME.KEY_NUM9;
		case KeyEvent.KEYCODE_POUND: 	return CanvasJ2ME.KEY_POUND;
		case KeyEvent.KEYCODE_STAR: 	return CanvasJ2ME.KEY_STAR;
		case KeyEvent.KEYCODE_UNKNOWN: 	return 0;
		}
		if(keyAndroid >= KeyEvent.KEYCODE_A && keyAndroid <= KeyEvent.KEYCODE_Z)
			return 'A'+ (keyAndroid - KeyEvent.KEYCODE_A);
		return 0;
	}
	
	public static String getSoftwareVersion() {
		try {
			PackageInfo packageInfo = Static.App.getPackageManager().getPackageInfo(Static.App.getPackageName(), 0);
			return packageInfo.versionName;
		} catch (PackageManager.NameNotFoundException e) {
			System.out.println("Package name not found");
		};
		return "1.0";
	}

}
